package com.htu.courseService.myCourse.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.htu.courseService.common.vo.R;
import com.htu.courseService.courseManage.vo.CourseQuery;
import com.htu.courseService.courseManage.vo.CoursesDto;
import com.htu.courseService.myCourse.service.MyCoursesService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/myCourse")
@RequiredArgsConstructor
@Slf4j
public class MyCourseController {
    private final MyCoursesService myCoursesService;

    /**
     * 我要学习此课程
     * @param courseId
     * @return
     */
    @PostMapping("/study")
    public R<?> create(Integer courseId){
        myCoursesService.studyCourses(courseId);
        return R.success();
    }

    /**
     * 查找我学习的课程分页
     * @param courseQuery
     * @return
     */
    @PostMapping("/page")
    public R<IPage<CoursesDto>> getCoursePage(@RequestBody CourseQuery courseQuery){
        IPage<CoursesDto> coursesDtoIPage = myCoursesService.getCoursePage(courseQuery);
        return R.success(coursesDtoIPage);
    }
}
